﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// 上一步按钮
	/// </summary>
	public partial class PreStepButton : UserControl
	{
		public PreStepButton()
		{
			this.InitializeComponent();
		}

        private string windowsTxt;
        
        /// <summary>
        /// 按钮上显示的文本
        /// </summary>
        public string SARWindowsTxt
        {
            get
            {
                windowsTxt = this.ButtonTxt.Text;
                return windowsTxt;
            }
            set
            {
                windowsTxt = value;
                this.ButtonTxt.Text = windowsTxt;
            }
        }

        /// <summary>
        /// 按钮被单击的事件
        /// </summary>
        public event MouseButtonEventHandler SARPreClick;
        private void preBtn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!isEnabled)
            {
                return;
            }

            this.gridText.Margin = new Thickness(25.69, 8.29, 0, 0);

            if (SARPreClick != null)
            {
                SARPreClick.Invoke(this, e);
            }
        }

        private bool isEnabled = true;

        /// <summary>
        /// 设置或者获取按钮是否处于可用状态
        /// </summary>
        public bool SARIsEnabled
        {
            set
            {
                isEnabled = value;
                if (isEnabled)
                {
                    this.Opacity = 1;
                }
                else
                {
                    this.Opacity = 0.5;
                }
            }
            get
            {
                return isEnabled;
            }
        }

        private void preBtn_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!isEnabled)
            {
                return;
            }
            this.gridText.Margin = new Thickness(24.69, 7.29, 0, 0);
        }

        private void preBtn_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!isEnabled)
            {
                return;
            }
            this.gridText.Margin = new Thickness(24.69, 7.29, 0, 0);
        }
	}
}